use crate::co;
use crate::decl::*;
use crate::gui::{*, privs::*};
use crate::kernel::privs::*;
use crate::msg::*;
use crate::prelude::*;
#[derive(Clone, Copy)]
pub struct HeaderItem<'a> {
owner: &'a Header,
index: u32,
}
impl<'a> HeaderItem<'a> {
#[must_use]
pub(in crate::gui) const fn new(owner: &'a Header, index: u32) -> Self {
Self { owner, index }
}
pub fn delete(&self) {
unsafe {
self.owner.hwnd()
.SendMessage(hdm::DeleteItem { index: self.index, })
}.unwrap();
}
pub fn focus(&self) {
unsafe {
self.owner.hwnd()
.SendMessage(hdm::SetFocusedItem { index: self.index })
}.unwrap();
}
#[must_use]
pub fn format(&self) -> co::HDF {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::FORMAT;
unsafe {
self.owner.hwnd()
.SendMessage(hdm::GetItem {
index: self.index,
hditem: &mut hdi,
});
}
hdi.fmt
}
#[must_use]
pub const fn index(&self) -> u32 {
self.index
}
#[must_use]
pub fn lparam(&self) -> isize {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::LPARAM;
unsafe {
self.owner.hwnd()
.SendMessage(hdm::GetItem {
index: self.index,
hditem: &mut hdi,
});
}
hdi.lParam
}
#[must_use]
pub fn order(&self) -> u32 {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::ORDER;
unsafe {
self.owner.hwnd()
.SendMessage(hdm::GetItem {
index: self.index,
hditem: &mut hdi,
});
}
hdi.iOrder as _
}
pub fn set_arrow(&self, arrow_state: HeaderArrow) {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::FORMAT;
hdi.fmt = self.format();
hdi.fmt &= !(co::HDF::SORTUP | co::HDF::SORTDOWN); hdi.fmt |= arrow_state.into();
unsafe {
self.owner.hwnd()
.SendMessage(hdm::SetItem {
index: self.index,
hditem: &mut hdi,
});
}
}
pub fn set_justify(&self, text_justification: HeaderJustify) {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::FORMAT;
hdi.fmt = self.format();
hdi.fmt &= !(co::HDF::LEFT | co::HDF::CENTER | co::HDF::RIGHT); hdi.fmt |= text_justification.into();
unsafe {
self.owner.hwnd()
.SendMessage(hdm::SetItem {
index: self.index,
hditem: &mut hdi,
});
}
}
pub fn set_lparam(&self, lparam: isize) {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::LPARAM;
hdi.lParam = lparam;
unsafe {
self.owner.hwnd()
.SendMessage(hdm::SetItem {
index: self.index,
hditem: &hdi,
});
}
}
pub fn set_order(&self, order: u32) {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::ORDER;
hdi.iOrder = order as _;
unsafe {
self.owner.hwnd()
.SendMessage(hdm::SetItem {
index: self.index,
hditem: &hdi,
});
}
}
pub fn set_text(&self, text: &str) {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::TEXT;
let mut wtext = WString::from_str(text);
hdi.set_pszText(Some(&mut wtext));
unsafe {
self.owner.hwnd()
.SendMessage(hdm::SetItem {
index: self.index,
hditem: &hdi,
});
}
}
pub fn set_width(&self, width: u32) {
let mut col_cx = SIZE::new(width as _, 0);
multiply_dpi(None, Some(&mut col_cx)).unwrap();
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::WIDTH;
hdi.cxy = col_cx.cx;
unsafe {
self.owner.hwnd()
.SendMessage(hdm::SetItem {
index: self.index,
hditem: &hdi,
});
}
}
#[must_use]
pub fn text(&self) -> String {
let mut hdi = HDITEM::default();
hdi.mask = co::HDI::TEXT;
let mut buf = WString::new_alloc_buf(MAX_PATH + 1); hdi.set_pszText(Some(&mut buf));
unsafe {
self.owner.hwnd()
.SendMessage(hdm::GetItem {
index: self.index,
hditem: &mut hdi,
});
}
let (psz, _) = hdi.raw_pszText();
unsafe { WString::from_wchars_nullt(psz) }.to_string()
}
}